/*
package org.itboys.mobile.service.pos;

import com.hz.sunday.tianjie.dao.TianJieOrderMapper;
import com.hz.sunday.tianjie.dao.TianJieOrderProductMapper;
import com.hz.sunday.tianjie.entity.mongo.TianJieMember;
import com.hz.sunday.tianjie.entity.mysql.TianJieOrder;
import com.hz.sunday.tianjie.entity.mysql.TianJieOrderProduct;
import com.hz.sunday.tianjie.entity.pos.TianJiePosResult;
import com.hz.sunday.tianjie.entity.pos.order.TianJiePosOrder;
import com.hz.sunday.tianjie.entity.pos.order.TianJiePosOrderProduct;
import com.hz.sunday.tianjie.partner.HttpHelper;
import com.hz.sunday.tianjie.service.mongo.TianJieMemberService;
import com.hz.sunday.tianjie.service.pos.TianJieMD5Util;
import org.apache.commons.lang.StringUtils;
import org.itboys.commons.utils.json.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

*/
/**
 * 作者：jiangxiong
 * 日期：2016年8月10日
 * 联系方式 ：empty90911@126.com
 * 描述：导入POS订单
 *//*

@Service
public class PosOrderService_old {
	
	protected  Logger logger = LoggerFactory.getLogger(getClass());
	
	public static String token = "QtKVfy67F3JSwFJqWef69Oxaa9rddTGKU0ZZqb8B+EU=";
	public static String url = "http://183.129.176.234:90/standard/Execute";
	@Autowired
	private TianJieOrderProductMapper orderProductMapper;
	@Autowired
	private TianJieOrderMapper orderMapper;
	@Autowired
	private TianJieMemberService memberService;
*/
/**
 * 推送订单到天街POS。多次推送。知道成功
 * @param StoreCode
 * @param ItemCode
 *//*


   
   public  void  OrderImportMuilt(TianJieOrder order,List<TianJieOrderProduct> orderProducts,String remark){
	Map<String,Object> param =new HashMap<String, Object>();
	param.put("Method", "OrderImport");
	//时间搓
	Long timeStamp=new Date().getTime();
	param.put("TimeStamp", timeStamp);
	TianJiePosOrder posOrder= new TianJiePosOrder();
	posOrder.OrderNo=order.getOrderNo();
	posOrder.OrderType="WS";
	posOrder.OrdertDate=new SimpleDateFormat("yyyy-MM-ss HH:mm:ss").format(new Date());
	TianJieMember shop = memberService.getById(order.getShopId());
	posOrder.SellBranch=shop.getNumber();
	posOrder.DeliveryBranch=shop.getNumber();
	posOrder.OriOrderAmt=order.getTotalAmount();
	posOrder.OrderAmt=order.getTotalAmount();
	posOrder.PayableAmt=order.getPayAmount();
	posOrder.CustId=String.valueOf(order.getMemberId());
	posOrder.CustName=order.getReceiveName();
	posOrder.CustPhone=order.getReceivePhone();
	posOrder.DeliveryAddress=order.getReceiveAddress();
	posOrder.Status=0;
	posOrder.Remark=remark;
	List<TianJiePosOrderProduct> posOrderProducts = new ArrayList<TianJiePosOrderProduct>();
		
	
	
	boolean isPos = false;
	int posNo=0;
	while(true){
		posNo++;
		for(int i =0;i<orderProducts.size();i++){
			TianJieOrderProduct  orderProduct = orderProducts.get(i);
			
			TianJiePosOrderProduct posOrderProduct = new TianJiePosOrderProduct();
			posOrderProduct.LineNo=i+1;
			//posOrderProduct.ItemCode=orderProduct.getProductNo();
			//2016年9月8日
			posOrderProduct.ItemCode=orderProduct.getProductItemCode();
			posOrderProduct.OriPrice=orderProduct.getProductPrice();
			posOrderProduct.SalePrice=orderProduct.getProductPrice();
			posOrderProduct.Qty=orderProduct.getProductNumber();
			posOrderProduct.SaleAmt=orderProduct.getProductPrice().multiply(new BigDecimal(orderProduct.getProductNumber()));
			posOrderProduct.Remark="";
			posOrderProducts.add(posOrderProduct);
		}
		String OrderMaster = JsonUtils.objectToString(posOrder);
		String OrderDetails=JsonUtils.objectToString(posOrderProducts);
		String data = "{\"OrderMaster\":" +OrderMaster +",\"OrderDetails\":" + OrderDetails +"}";
		logger.info("订单带入POST:data＝"+data);
		
		String SignatureParam = token+timeStamp+data;

		logger.info("订单带入POST:签名参数＝"+SignatureParam);
		String Signature =TianJieMD5Util.MD5(SignatureParam);
		param.put("data", data);
		param.put("Signature", Signature.toUpperCase());
			
	    String responsResult= HttpHelper.doPostWithUtf8(url, param);
	    if(StringUtils.isNotBlank(responsResult)
	    		&&!responsResult.equalsIgnoreCase("fail")){
	    	TianJiePosResult orderResult=  JsonUtils.jsonToObject(TianJiePosResult.class, responsResult);
	    	if(orderResult.ResCode.equals(0)){
	    		isPos=true;
	    	}  
	    	
	    }
	    //最多导入五次
	    if(isPos==true||posNo>=5){
	    	break;
	    }
	    logger.info("订单带入，第"+posNo+"次导入"+":订单返回的POS返回结果＝"+responsResult);
	  //  System.out.println("订单返回的POS返回结果"+responsResult);
		} 
		//修改订单是否pos状态
		if(isPos==true){
			orderMapper.posOrder(order.getId());
		}
   }
   //2016年9月18日。手动后台推送到POS
   public  String  OrderImportOnHand(Long orderId){
		Map<String,Object> param =new HashMap<String, Object>();
		
		TianJieOrder order = orderMapper.find(orderId);
		param.put("orderId", order.getId());
		List<TianJieOrderProduct> orderProducts=orderProductMapper.select(param);
		param.clear();
		
		
		param.put("Method", "OrderImport");
		//时间搓
		Long timeStamp=new Date().getTime();
		param.put("TimeStamp", timeStamp);
		TianJiePosOrder posOrder= new TianJiePosOrder();
		posOrder.OrderNo=order.getOrderNo();
		posOrder.OrderType="WS";
		posOrder.OrdertDate=new SimpleDateFormat("yyyy-MM-ss HH:mm:ss").format(new Date());
		TianJieMember shop = memberService.getById(order.getShopId());
		posOrder.SellBranch=shop.getNumber();
		posOrder.DeliveryBranch=shop.getNumber();
		posOrder.OriOrderAmt=order.getTotalAmount();
		posOrder.OrderAmt=order.getTotalAmount();
		posOrder.PayableAmt=order.getPayAmount();
		posOrder.CustId=String.valueOf(order.getMemberId());
		posOrder.CustName=order.getReceiveName();
		posOrder.CustPhone=order.getReceivePhone();
		posOrder.DeliveryAddress=order.getReceiveAddress();
		posOrder.Status=0;
		posOrder.Remark="";
		

		List<TianJiePosOrderProduct> posOrderProducts = new ArrayList<TianJiePosOrderProduct>();
			
		
		
		
		
		for(int i =0;i<orderProducts.size();i++){
			TianJieOrderProduct  orderProduct = orderProducts.get(i);
			
			TianJiePosOrderProduct posOrderProduct = new TianJiePosOrderProduct();
			posOrderProduct.LineNo=i+1;
			//posOrderProduct.ItemCode=orderProduct.getProductNo();
			//2016年9月8日
			posOrderProduct.ItemCode=orderProduct.getProductItemCode();
			posOrderProduct.OriPrice=orderProduct.getProductPrice();
			posOrderProduct.SalePrice=orderProduct.getProductPrice();
			posOrderProduct.Qty=orderProduct.getProductNumber();
			posOrderProduct.SaleAmt=orderProduct.getProductPrice().multiply(new BigDecimal(orderProduct.getProductNumber()));
			posOrderProduct.Remark="";
			posOrderProducts.add(posOrderProduct);
			}
		//	orderProducts.add(orderProduct2);
		String OrderMaster = JsonUtils.objectToString(posOrder);
		String OrderDetails=JsonUtils.objectToString(posOrderProducts);
		//String data="{\"OrderMaster\":{\"OrderNo\":\"12345789\",\"OrderType\":\"WS\",\"OrdertDate\":\"1470901782411\",\"SellBranch\":\"01001\",\"DeliveryBranch\":\"01001\",\"OriOrderAmt\":\"150\",\"OrderAmt\":\"120\",\"PayableAmt\":\"100\",\"CustId\":\"375\",\"CustName\":\"江雄\",\"CustPhone\":\"18968173081\",\"DeliveryAddress\":\"杭州皇姑山路\",\"Status\":0,\"Remark\":\"测试订单主体备注\"},\"OrderDetails\":[{\"LineNo\":1,\"ItemCode\":\"6901028315425\",\"OriPrice\":\"7\",\"SalePrice\":\"7\",\"Qty\":\"3\",\"SaleAmt\":\"21\",\"Remark\":\"测试订单商品备注1\"},{\"LineNo\":2,\"ItemCode\":\"6901028114448\",\"OriPrice\":\"50\",\"SalePrice\":\"47\",\"Qty\":\"1\",\"SaleAmt\":\"47\",\"Remark\":\"测试订单商品备注2\"}]}";
		//签名
		//String EndDate="2020-08-26";*//*

		String data = "{\"OrderMaster\":" +OrderMaster +",\"OrderDetails\":" + OrderDetails +"}";
		System.out.println("data---------"+data);
		String SignatureParam = token+timeStamp+data;
		System.out.println("签名参数---"+SignatureParam);
		String Signature =TianJieMD5Util.MD5(SignatureParam);
		param.put("data", data);
		param.put("Signature", Signature.toUpperCase());
			
	    String responsResult= HttpHelper.doPostWithUtf8(url, param);
	    System.out.println("订单返回的POS返回结果"+responsResult);
	    if(StringUtils.isBlank(responsResult)
	    		||responsResult.equalsIgnoreCase("fail")){
	    	return "网络连接失败或其他未知错误。";
	    }else{
	    	TianJiePosResult orderResult=  JsonUtils.jsonToObject(TianJiePosResult.class, responsResult);
	    	if(orderResult.ResCode.equals(0)){
	    		//if(isPos==true){
	    			orderMapper.posOrder(orderId);
	    		//}
	    		return "推送成功";
	    		
	    	}else{
	    		return orderResult.Msg;
	    	}
	    	
	    }
	} 
}
*/
